package cn.com.wangluotongxin.member.event;

import cn.com.wangluotongxin.member.rabbitmq.listener.MemberRabbitmqConstants;
import cn.com.wangluotongxin.member.rabbitmq.pojo.MemberInfoUpdatePojo;
import cn.com.wangluotongxin.rabitmq.service.RabbitmqCommonPushService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
public class MemberUpdatePushEventHandler implements ApplicationListener<MemberUpdatePushEvent> {

    @Autowired
    private RabbitmqCommonPushService commonPushService;

    @Async
    @Override
    public void onApplicationEvent(MemberUpdatePushEvent event) {
        MemberInfoUpdatePojo pojo = new MemberInfoUpdatePojo()
                .setId(event.getPojo().getId())
                .setPhone(event.getPojo().getPhone())
                .setName(event.getPojo().getName())
                .setIdCard(event.getPojo().getIdCard())
                .setHeadImg(event.getPojo().getHeadImg());
        commonPushService.push(MemberRabbitmqConstants.MEMBER_INFO_UPDATE_PUSH, pojo);
    }
}
